import Util from "./utils/Util";

// @inspector
export default class BasePanel<T> extends cc.Component {

    protected setData(data: Optional<T>) {
        //改变一个属性对应的表现
        let changeOne = (key: string) => {
            return new Promise((resolve, reject) => {
                let value: any = data[key];

                if (this[key] instanceof cc.Label) {//Label类型
                    this[key].string = value;
                    resolve();
                } else if (this[key] instanceof cc.Sprite) {//Sprite类型
                    this[key].spriteFrame = value;
                    resolve();
                    //先判断是否为0，不然if条件中判断为false不存在
                } else if (this[key] === 0 || Util.getDateType(this[key]) === "Number" || Util.getDateType(this[key]) === "String" || Util.getDateType(this[key]) === "Array" || Util.getDateType(this[key]) === "Object") {
                    this[key] = value;
                    return resolve();
                } else {
                    console.warn(`${key} 值的类型不确定 ${Util.getDateType(this[key])}`);
                }
            });
        };
        for (let key of Object.keys(data)) {
            changeOne(key)
        }
    }

    protected onShow() {
        // console.log('我被打开了');
    }

    protected onHide() {
        // console.log('我被关闭了');
    }
}
